package org.smr.dev.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.smr.dev.utils.CodeConst;
import org.smr.dev.vo.Module;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("project")
public class ProjectController {

    @RequestMapping("index")
    public String index( Model model){

        return "/project/project-index";
    }

    @Value("${smr.project.path}")
    private String projectPath;

    @ResponseBody
    @RequestMapping("save")
    public Map saveProjectInfo(@RequestBody  Map params){

        String moduleName = MapUtils.getString(params,"moduleName");
        String projectName = MapUtils.getString(params,"projectName");
        String packageName = MapUtils.getString(params,"packageName");

        Module module = new Module();
        module.setName(moduleName);
        CodeConst.put(CodeConst.MODULE_DEFINE,module);
        CodeConst.put(CodeConst.PROJECT_DIR, projectPath);
        CodeConst.put(CodeConst.PROJECT_NAME, projectName);

        CodeConst.put(CodeConst.PROJECT_PACKAGE_VARIABLE, packageName);
        Map message = new HashMap();
        message.put("code",1);
        message.put("msg","success");
        return message;
    }

}
